package com.lagou.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

import java.util.Map;

import static org.apache.dubbo.rpc.Constants.DEPRECATED_KEY;


@Activate(group = {CommonConstants.CONSUMER, CommonConstants.PROVIDER})
public class TransportIPFilter implements Filter {

    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        long startTime = System.currentTimeMillis();
        try {
            Map<String, String> contextAttachments = RpcContext.getContext().getAttachments();
            contextAttachments.put("ip",RpcContext.getContext().getLocalHost());
            // 执行方法
            return invoker.invoke(invocation);
        } finally {
            System.out.println("invoke time:" + (System.currentTimeMillis() - startTime) + "毫秒");
        }

    }


}
